import { Controller, Get, Param,ParseIntPipe,Post,Body,Delete,Req} from '@nestjs/common';
import { UserService } from './user.service';
import {warpperResponse} from '../../utils/index'
@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) {
    
  }
  @Get('info')
  getUserByToken(@Req() request,){
    console.log(request.user);
    
    return warpperResponse(this.userService.findByUsername(request.user.username),'获取用户信息成功')
  }
  @Get(':id')
  getUser(@Param('id',ParseIntPipe) id :number) {
    return this.userService.findOne(id)
  }
  @Get()
  getAlluser() {
    return this.userService.findAll()
  }
  @Post()
  createUser(@Body() createUserDto) {
    return this.userService.create(createUserDto)
  }
  @Delete(':id')
  // 定义一个remove方法，接收一个ParseIntPipe类型的参数id，返回类型为number
remove(@Param('id',ParseIntPipe) id :number) {
    // 调用userService的remove方法，传入id参数，返回该方法的结果
    return this.userService.remove(id)
  }
}
